@section('content')
<div class="am-g m-user">
	<div class="am-u-md-12">
		<div class="m-user-title am-cf">
			<h1>我的账户</h1>
			<!-- 
			<span class="free-tip">订单满500元免运费</span>
			 -->
		</div>
	</div>
	<div class="am-u-md-12">
		<div class="m-user-hd">
			<ul class="am-cf">
				<li><a href="{{URL::to('user/order-list')}}">我的订单</a></li>
				<li><a href="{{URL::to('user/address-list')}}">地址</a></li>
				<li><a href="{{URL::to('user/info')}}">登陆资料</a></li>
				<li><a href="{{URL::to('user/favorite-list')}}">收藏夹</a></li>
			</ul>
		</div>
		<div class="m-user-bd">
			<ul>
				<li>
					<h3>收藏夹</h3>
					<span>查看收藏夹，加入喜爱的商品，购买收藏的商品</span>
				</li>
			</ul>
			
			<table class="am-table m-cart-table">
			    <thead>
			        <tr>
			            <th>商品</th>
			            <th>价格</th>
			            <th>操作</th>
						<th>删除</th>
			        </tr>
			    </thead>
			    <tbody>
					@foreach($favorites as $f)
					@if (!empty($f->product))
			        <tr data-favorite_id = "{{$f->id}}"
			        	data-id="{{$f->product->id}}"  data-name="{{$f->product->name}}" data-enname="{{$f->product->enname}}" 
			            data-image="{{$f->product->image}}" data-price="{{$f->product->discount_price > 0 ? $f->product->discount_price : $f->product->price}}"
			            data-size_id="{{$f->size_id}}" data-size="{{empty($f->sizeer) ? '' : $f->sizeer->size }}"
			            data-color_id="{{$f->color_id}}" data-color="{{empty($f->colorer) ? '' : $f->colorer->color }}">
			            <td>
							<div class='m-cart-item am-cf'>
								<a href="{{URL::to('product',$f->product_id)}}"><img src='{{Images::url($f->product->image,72,72)}}'></img><a>
						  		<div class='m-cart-item-bd'>
						  			<div class='name'>{{$f->product->brand}}</div>
						  			<div class='name'>{{$f->product->name}}</div>
									@if (!empty($f->size))
			                        <div class='name'>尺寸:{{$f->size}}</div>
									@endif
									@if (!empty($f->color))
			                        <div class='name'>颜色:{{$f->color}}</div>
									@endif
						  		</div>
							</div>
						</td>
			            <td>¥ {{$f->product->discount_price > 0 ? number_format($f->product->discount_price,2) : number_format($f->product->price,2)}} 元</td>
			            <td >
			            	@if(!empty($f->size_id))
			            		@if(!empty($f->sizeer))
			            			<button type="button" class="m-btn m-btn-normal m-add-product-btn" style="margin-left: 0;">加入购物车</button>
			            		@else
			            			<button type="button" class="m-btn m-btn-normal disable" style="margin-left: 0;">已售完</button>
			            		@endif
			            	@elseif(!empty($f->color_id))
			            		@if(!empty($f->colorer))
			            			<button type="button" class="m-btn m-btn-normal m-add-product-btn" style="margin-left: 0;">加入购物车</button>
			            		@else
			            			<button type="button" class="m-btn m-btn-normal disable" style="margin-left: 0;">已售完</button>
			            		@endif
			            	@else
			            		@if($f->product->quantity > 0)
			            			<button type="button" class="m-btn m-btn-normal m-add-product-btn" style="margin-left: 0;">加入购物车</button>
			            		@else
			            			<button type="button" class="m-btn m-btn-normal disable" style="margin-left: 0;">已售完</button>
			            		@endif
			            	@endif
			            </td>
						<td><span class='am-close close-btn delete'>&times;</span></td>
			        </tr>
			        @endif
					@endforeach
			    </tbody>
			</table>
			
			<div class="am-fr">
			  	<!-- 分页列表 -->
			  	{{$favorites->links("admin.slider")}}
			 </div>
		</div>
	</div>
    </div>
</div>

@stop
@section('script')
<script type="text/javascript">
	$(function(){
		$(document).on("click",".m-add-product-btn",function(e){
			var $btn = $(this);
			var data = $btn.closest("tr").data();
			$.cart.add(data);
			e.stopPropagation();
		});

		$(document).on("click",".delete",function(){
			var $tr = $(this).closest('tr');
			var data = $tr.data();
			var options = {
					content:'确认删除吗？',
					ok:function(){
						$.post("{{URL::to('user/favorite/delete')}}",{id:data.favorite_id},function(result){
							if (result.success){
								$tr.remove();
							}
						});
					}
			};
			$.dialog.confirm(options);
		});
	});
</script>
@stop
